package com.douziit.meilianoa.controller;


import com.douziit.meilianoa.base.request.PageRequest;
import com.douziit.meilianoa.base.response.ResponseData;
import com.douziit.meilianoa.base.response.ResponseUtil;
import com.douziit.meilianoa.entity.Customer;
import com.douziit.meilianoa.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户控制器类
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 添加客户
     */
    @PostMapping("/addCustomer")
    public ResponseData addCustomer(@RequestBody Customer customer){

        customerService.save(customer);
        return ResponseUtil.jsonSuccess(0);
    }

    /**
     * 客户列表
     */
    @PostMapping("/listCustomer")
    public ResponseData listCustomer(){
        List<Customer> list = customerService.list();
        return ResponseUtil.jsonSuccess(list);
    }

    /**
     * 编辑信息
     */
    @PostMapping("/changeCustomer")
    public ResponseData changeCustomer(@RequestBody Customer customer){
        customerService.updateById(customer);
        return ResponseUtil.jsonSuccess(0);
    }

    /**
     * 删除客户
     */
    @PostMapping("/deleteCustomer")
    public ResponseData deleteCustomer(@RequestBody PageRequest req){

        customerService.removeById(req.getCustomerId());
        return ResponseUtil.jsonSuccess(0);
    }
}
